// house_pkg/pages/locate/index.ts
import qqMap from '../../../utils/qqMap'
Page({
  goBuilding(ev) {
    wx.navigateTo({
      url: '/house_pkg/pages/building/index?point=' + ev.mark.point
    })
  },
  onLoad() {
    this.getLocation()
  },
  async getLocation() {
    const { latitude, longitude } = await wx.getLocation()
    console.log(latitude, longitude)
    this.getPoint(latitude, longitude)
  },
  async chooseLocation() {
    const { latitude, longitude } = await wx.chooseLocation()
    console.log(latitude, longitude);
    this.getPoint(latitude, longitude)
  },
  getPoint(latitude, longitude) {
    qqMap.reverseGeocoder({
      location:[latitude, longitude].join(','),
      success:(res) => {
        console.log(res.result.address)
        this.setData({
          address: res.result.address
        })
      }
    })
    qqMap.search({
      keyword: '小区',
      location: [latitude, longitude].join(','),
      page_size: 10,
      success: (res) => {
        console.log(res)
        this.setData({
          points: res.data
        })
      }
    })
  }
})